package gui.components.objectinfo;

import gui.GUI;
import gui.components.map.objects.objRadialGrid;
import gui.components.map.objects.objRasterGrid;

import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import lookandfeel.colorScheme;
import lookandfeel.customButton;

public class View_Toggles {
	
	private int rasterSize = 30;
	private int radialSize = 15;
	
	public void setRasterSize(int _size){
		if(_size > 0 && _size < 100){
			rasterSize = _size;
		}
	}
	public int getRasterSize(){
		return rasterSize;
	}
	public void setRadialSize(int _size){
		if(_size > 5 && _size < 25){
			radialSize = _size;
		}
	}
	public int getRadialSize(){
		return radialSize;
	}
	
	public JPanel createPanelElements(){
		//Get look and feel instance
		final colorScheme lookAndFeel = colorScheme.getColorScheme();

		//Create main panel
		JPanel pnlMain = new JPanel(new GridLayout(4,1));
		JPanel pnlTheme = new JPanel();
		pnlTheme.add(new JLabel("Change theme"));
		customButton redTheme = new customButton("Red");
		customButton darkGrayTheme = new customButton("Dark Gray");
		customButton randomTheme = new customButton("Random");
		
		if(lookAndFeel.getSelectedTheme() == "Red"){
			redTheme.setEnabled(false);
			darkGrayTheme.setEnabled(true);
		}
		else if(lookAndFeel.getSelectedTheme() == "Dark Gray"){
			redTheme.setEnabled(true);
			darkGrayTheme.setEnabled(false);
		}
		else{
			redTheme.setEnabled(true);
			darkGrayTheme.setEnabled(true);
		}
		
		redTheme.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				lookAndFeel.setTheme("Red");
				GUI.Initialize();
			}
		});

		darkGrayTheme.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				lookAndFeel.setTheme("Dark Gray");
				GUI.Initialize();
			}
		});

		randomTheme.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				lookAndFeel.setTheme("Random");
				GUI.Initialize();
			}
		});
		pnlTheme.add(redTheme);
		pnlTheme.add(darkGrayTheme);
		pnlTheme.add(randomTheme);
		
		JPanel pnlGrid = new JPanel();
		pnlGrid.add(new JLabel("Grid"));
			customButton btnNone = new customButton("None");
			btnNone.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					GUI.getMap().ClearGrid();
				}
			});
			final customButton btnRaster = new customButton("Raster");
			btnRaster.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					//Raster grid aanmaken en toevoegen
					objRasterGrid _gridraster = new objRasterGrid();
					_gridraster.SetColor(new Color(180,180,180));
					_gridraster.SetGridboxheight(getRasterSize()); 
					_gridraster.SetGridboxwidth(getRasterSize());
					GUI.getMap().ToggleGrid(_gridraster);
				}
			});
			final customButton btnRadial = new customButton("Radial");
			btnRadial.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					//Radial grid aanmaken en toevoegen
					objRadialGrid _gridradial = new objRadialGrid();
					_gridradial.SetColor(new Color(180,180,180));
					_gridradial.SetTextColor(new Color(165,165,165));
					_gridradial.setAantal(getRadialSize());

					GUI.getMap().ToggleGrid(_gridradial);
				}
			});
			customButton btnBoth = new customButton("Both");
			btnBoth.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					//Beide grids aanmaken en toevoegen
					
					//Rastergrid
					objRasterGrid _gridraster = new objRasterGrid();
					_gridraster.SetColor(new Color(180,180,180));
					_gridraster.SetGridboxheight(getRasterSize());
					_gridraster.SetGridboxwidth(getRasterSize());
					
					//Radialgrid
					objRadialGrid _gridradial = new objRadialGrid();
					_gridradial.setAantal(getRadialSize());
					_gridradial.SetColor(new Color(180,180,180));
					_gridradial.SetTextColor(new Color(165,165,165));
					
					GUI.getMap().ToggleGrids(_gridraster, _gridradial);	
				}
			});
		pnlGrid.add(btnNone);
		pnlGrid.add(btnRaster);
		pnlGrid.add(btnRadial);
		pnlGrid.add(btnBoth);
		pnlGrid.setBorder(BorderFactory.createEmptyBorder(5, 35, 0, 0));
		
		JPanel pnlRasterSize = new JPanel();
		pnlRasterSize.add(new JLabel("Raster size"));
			customButton btnIncreaseRaster = new customButton("+");
			btnIncreaseRaster.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					setRasterSize(getRasterSize() + 10);
					btnRaster.doClick();
				}
			});
		customButton btnDecreaseRaster = new customButton("-");
		btnDecreaseRaster.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				setRasterSize(getRasterSize() - 10);
				btnRaster.doClick();
			}
		});
		pnlRasterSize.add(btnIncreaseRaster);
		pnlRasterSize.add(btnDecreaseRaster);
		pnlRasterSize.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 30));
		
		JPanel pnlRadialSize = new JPanel();
		pnlRadialSize.add(new JLabel("Radial number"));
			customButton btnIncreaseRadial = new customButton("+");
			btnIncreaseRadial.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					setRadialSize(getRadialSize() + 1);
					btnRadial.doClick();
				}
			});
		customButton btnDecreaseRadial = new customButton("-");
		btnDecreaseRadial.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				setRadialSize(getRadialSize() - 1);
				btnRadial.doClick();
			}
		});
		pnlRadialSize.add(btnIncreaseRadial);
		pnlRadialSize.add(btnDecreaseRadial);
		pnlRadialSize.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 45));

		pnlMain.add(pnlTheme);
		pnlMain.add(pnlGrid);
		pnlMain.add(pnlRasterSize);
		pnlMain.add(pnlRadialSize);
		
		return pnlMain;
	}
}
